package com.pctx.bibadevicemanager.controller;

import com.pctx.bibacommon.result.Result;
import com.pctx.bibadevicemanager.pojo.DeviceUser;
import com.pctx.bibadevicemanager.service.DeviceUserService;
import com.pctx.bibadevicemanager.service.TrackerSharePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chason on 2018/3/12.17:00
 */
@RestController
@RequestMapping("tracker")
public class TrackerController {
    @Autowired
    private DeviceUserService deviceUserService;
    @Autowired
    private TrackerSharePermissionService trackerSharePermissionService;

    @PostMapping("shareDevice")
    public Result shareDevice(@RequestParam(value = "deviceUuid", required = true) String deviceUuid,
                              @RequestParam(value = "userUuid", required = true) String userUuid) throws Exception {
        return deviceUserService.shareDevice(deviceUuid, userUuid);
    }

    @GetMapping("shareList")
    public Result shareList(@RequestParam(value = "deviceUuid", required = true) String deviceUuid) throws Exception {
        return deviceUserService.shareList(deviceUuid);
    }


    @GetMapping("stopShare")
    public Result stopSahre(@RequestParam(value = "deviceUserUuid", required = true) String deviceUserUuid) throws Exception {
        return deviceUserService.stopSahre(deviceUserUuid);
    }

    @PostMapping("updateTrackerPermission")
    public Result updateTracherPermission(@RequestParam(value = "uuid", required = true) String uuid,
                                          @RequestParam(value = "trackerFlag", required = false) Byte trackerFlag,
                                          @RequestParam(value = "fenceFlag", required = false) Byte fenceFlag) throws Exception {

        return trackerSharePermissionService.updateTrackerPermission(uuid, trackerFlag, fenceFlag);
    }

}
